package com.duplicate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CountDuplicateNumbers {
public static void main(String[] args) {
	List<Integer> list=new ArrayList<Integer>();
	list.add(8);list.add(8);list.add(9);list.add(2);list.add(8);list.add(2);list.add(7);
	/*Map<Integer, Integer> map=new HashMap<Integer, Integer>();
	for(Integer temp:list){
		Integer count=map.get(temp);
		map.put(temp, (count==null)?1:count+1);
	}
	for(Map.Entry<Integer, Integer> entry:map.entrySet()){
		System.out.println("Key : "+entry.getKey()+"\tValue : "+entry.getValue());
	}*/
	findRepeatedElement(list);
}
public static void findRepeatedElement(List<Integer> list){
	Map<Integer, Integer> map=new HashMap<Integer, Integer>();
	for(Integer temp:list){
		Integer count=map.get(temp);
		//map.put(temp, value);
		map.put(temp, (count==null)?1:count+1);
	}
	for(Map.Entry<Integer, Integer> entry:map.entrySet()){
		System.out.println("Key : "+entry.getKey()+"\tValue : "+entry.getValue());
	}
}
}
